<template>
  <div class="container">
    <div class="selfInfo">
      <div class="leftImg">
        <img src="@/assets/common/组 5823.png" alt="" />
      </div>
      <div class="rightBox">
        <div class="name">
          {{ userInfo.userName ? userInfo.userName : '未登录' }}
        </div>
        <div class="labelBox">
          <div class="label greenColor">
            {{ userInfo.roleName ? userInfo.roleName : '未登录' }}
          </div>
          <div class="label">
            {{ userInfo.departmentName ? userInfo.departmentName : '未登录' }}
          </div>
        </div>
      </div>
    </div>

    <div class="cardBox">
      <div class="cardItem" @click="goSelf">
        <div class="leftImg">
          <img src="@/assets/common/组 7907.png" alt="" />
          <div>个人信息</div>
        </div>
        <div class="rightImg">
          <img src="@/assets/组 5411@2x.png" alt="" />
        </div>
      </div>
      <div class="cardItem" @click="loginOut">
        <div class="leftImg">
          <img src="@/assets/common/组 7906.png" alt="" />
          <div>退出登录</div>
        </div>
        <div class="rightImg">
          <img src="@/assets/组 5411@2x.png" alt="" />
        </div>
      </div>
    </div>

    <van-popup v-model="show" closeable>
      <div class="popBox">
        <div class="titlePic">
          <img src="@/assets/common/error-circle-filled.png" alt="" />
        </div>
        <div class="content">确定退出登录吗？</div>
        <div class="btnBox">
          <div class="cancel" @click="show = false">取消</div>
          <div class="sure" @click="confirmLoginOut">确定</div>
        </div>
      </div>
    </van-popup>
    <tabbar :activeIndex.sync="nowActive"></tabbar>
  </div>
</template>

<script>
import { userInfoApi } from '@/api/index'
import tabbar from '@/components/tabbar'
export default {
  name: 'minePage',
  props: {},
  components: {
    tabbar,
  },
  data() {
    return {
      nowActive: 3,
      userInfo: {},
      isLoginMsg: {},
      show: false,
    }
  },
  created() {
    this.isLoginMsg = JSON.parse(sessionStorage.getItem('loginInfo'))
    if (!this.isLoginMsg) {
      this.confirmLoginOut()
    }
    this.getUserInfo()
  },
  methods: {
    loginOut() {
      this.show = true
    },
    confirmLoginOut() {
      sessionStorage.clear()
      this.$router.push('/login')
      this.show = false
    },
    async getUserInfo() {
      const res = await userInfoApi({ id: this.isLoginMsg.userId })
      this.userInfo = res.data
    },
    goSelf() {
      this.$router.push('/selfInfo')
    },
  },
  mounted() {},
  watch: {},
  computed: {},
  filters: {},
}
</script>

<style scoped lang="scss">
.container {
  height: 100vh;
  width: 100%;
  // background: linear-gradient(180deg, #e6f8ee 0%, #fff 100%);
  background-color: #f5f7f6;
}
.selfInfo {
  box-sizing: border-box;
  background-image: url('@/assets/common/组 5846@2x.png');
  background-repeat: no-repeat;
  background-size: 100% 100%;
  width: 100%;
  height: 252px;
  display: flex;
  align-items: center;
  // padding-top: 40px;
  padding-left: 28px;
  .leftImg {
    width: 72px;
    height: 72px;
    margin-right: 12px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .rightBox {
    .name {
      font-size: 16px;
      color: #ffffff;
      font-weight: bold;
    }
    .labelBox {
      display: flex;
      padding-top: 12px;
      .label {
        // width: 50px;
        height: 24px;
        background: #0062d3;
        border-radius: 12px;
        font-size: 12px;
        color: #dcecff;
        text-align: center;
        line-height: 24px;
        margin-right: 8px;
        padding: 2px 12px;
      }
      .greenColor {
        color: #0060d5;
        background: #dbebff;
      }
    }
  }
}
.cardBox {
  padding: 16px;
  transform: translateY(-80px);
  .cardItem {
    background-color: #fff;
    height: 48px;
    // width: 100%;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    margin-top: 16px;
    .leftImg {
      display: flex;
      align-items: center;
      img {
        width: 24px;
        height: 24px;
        margin-right: 8px;
      }
    }
    .rightImg {
      img {
        width: 24px;
        height: 24px;
      }
    }
  }
}
.popBox {
  width: 60vw !important;
  padding-top: 40px;
  .titlePic {
    text-align: center;
    img {
      width: 48px;
      height: 48px;
    }
  }
  .content {
    text-align: center;
    padding: 20px 0;
  }
  .btnBox {
    display: flex;
    text-align: center;
    border-top: 1px solid #eeeff1;
    .cancel {
      width: 50%;
      height: 40px;
      line-height: 40px;
      border-right: 1px solid #eeeff1;
    }
    .sure {
      width: 50%;
      height: 40px;
      line-height: 40px;
    }
  }
}
</style>
